package jwdt.xadmin.added.action;

import jwdt.common.action.BaseAction;
import jwdt.common.util.CacheUtil;
import jwdt.xadmin.added.bean.TLinktype;
import jwdt.xadmin.added.service.LinktypeManageService;

import com.ezerg.db.Jdb;
import com.ezerg.db.ext.PageUtil;
import com.ezerg.web.Form;
import com.ezerg.web.Module;
import com.ezerg.web.Page;
import com.ezerg.web.annotation.Controller;
import com.ezerg.web.annotation.RequestMapping;

@Controller("/xadmin/added")
public class LinktypeManageAction extends BaseAction {
	
	private LinktypeManageService linktypeManageService = (LinktypeManageService)app.getBean("linktypeManageService");
	
	@RequestMapping("/listLinktype")
	public Page doList(Form f, Module m) throws Exception {
		PageUtil pu = (PageUtil)f.copy2Class(PageUtil.class);
		TLinktype lt = (TLinktype)f.copy2Class(TLinktype.class);
		return m.getWritePage(f, linktypeManageService.doList(pu, lt).toJson());
	}
	
	@RequestMapping("/addLinktype")
	public Page doAddact(Form f, Module m) throws Exception {
		TLinktype obj = (TLinktype)f.copy2Class(TLinktype.class);
		return m.getWritePage(f, linktypeManageService.doAddact(obj));
	}
	
	@RequestMapping("/editLinktype")
	public Page doEditact(Form f, Module m) throws Exception {
		int id = f.getInt("id");
		TLinktype obj = (TLinktype)f.copy2Class(TLinktype.class);
		return m.getWritePage(f, linktypeManageService.doEditact(obj, id));
	}
	
	@RequestMapping("/delLinktype")
	public Page doDel(Form f, Module m) throws Exception {
		int id = f.getInt("id");
		return m.getWritePage(f, linktypeManageService.doDelact(id));
	}
	
	@RequestMapping("/updateState")
	public Page doUpdateState(Form f, Module m) throws Exception {
		int id = f.getInt("id");
		int result = f.getInt("result");
		return m.getWritePage(f, linktypeManageService.doUpdateState(id, "zt="+result));
	}
	
	@RequestMapping("/listLinktypeForTree")
	public Page doListForTree(Form f, Module m) throws Exception {
    	return m.getWritePage(f, linktypeManageService.doListLinktypeForTree());
	}
	
	@RequestMapping("/listLinktypeForCombox")
	public Page doListForCombox(Form f, Module m) throws Exception {
		//生成json字符串
    	return m.getJsonPage(f, Jdb.get().query("select id, name from t_Linktype where zt=1 ORDER BY id asc", CacheUtil.C0));
	}
	
	@RequestMapping("/linktypeWindow")
	public Page doLoad(Form f, Module m) throws Exception {
		int id = f.getInt("id");
		f.add("obj", linktypeManageService.doLoad(id));
		return m.findPage("/xadmin/added/linktypeWindow");
	}
}
